package com.huangd.platform.common.utils;

import lombok.Data;
import org.apache.http.HttpStatus;

/**
 * 返回数据
 *
 * @author huangd
 */

@Data
public class R<T> {
	private int code;
	private String msg;
	private T data;

	public R() {
		this.code = 0;
		this.msg = "success";
	}

	public static R error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
	}

	public static R error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}

	public static R error(int code, String msg) {
		R r = new R();
		r.setCode(code);
		r.setMsg(msg);
		return r;
	}

	/*public static R ok(String msg) {
		R r = new R();
		r.setMsg(msg);
		return r;
	}*/

	public static R ok(Object o) {
		R r = new R();
		r.setData(o);
		return r;
	}

	public static R ok() {
		return new R();
	}

}
